package org.cloud.jiangyoutourism.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.cloud.jiangyouapi.clients.UserClient;
import org.cloud.jiangyoucommon.common.Result;
import org.cloud.jiangyoutourism.service.SightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 景点信息 Controller层
 * @author liupy
 * @since 2024-01-07 16:05:12
 */
@Slf4j
@RestController
@RequestMapping("/sights")
@Api(value = "景点相关接口", tags = "景点接口")
public class SightsController {
    @Autowired
    private SightsService sightsService;

    @Autowired
    private UserClient userClient;

    @ApiOperation(value = "获取景点列表")
    @GetMapping("/list")
    public Result getAllSights() {
        try {
            return sightsService.getAllSights();
        } catch (Exception e) {
            log.error("获取景点列表接口异常：{}", e.getMessage(),e);
            return Result.fail("获取景点列表异常");
        }
    }

    @ApiOperation(value = "根据id查询景点信息")
    @GetMapping("/{id}")
    public Result queryById(@ApiParam("景点id") @PathVariable("id") String sightsId) {
        log.info("根据id查询景点信息接口入参，sightsId={}",sightsId);
        try {
            return sightsService.queryById(sightsId);
        } catch (Exception e) {
            log.error("根据id查询景点信息接口异常：{}", e.getMessage(),e);
            return Result.fail("根据id查询景点信息异常");
        }
    }

    @ApiOperation(value = "根据名称模糊查询景点信息")
    @GetMapping("/sightsInfo")
    public Result queryByUserName(@RequestParam("name") String name) {
        log.info("根据名称模糊查询景点信息接口入参，sightsName={}",name);
        try {
            return sightsService.queryByUserName(name);
        } catch (Exception e) {
            log.error("根据名称模糊查询景点信息接口异常：{}", e.getMessage(),e);
            return Result.fail("根据名称模糊查询景点信息异常");
        }
    }
}

